#ifndef AST_TO_JSON_H
#define AST_TO_JSON_H
#pragma once

#include <iostream>
#include <memory>
#include <list>
#include "cyclone_parser_support.h"
#include "macros.h"
#include "json.hpp"
#include "parse_option.hpp"

using Json = nlohmann::json;

namespace cyclone::parser
{
	class PARSER_LIBRARY_EXPORT AstToJson
	{
	public:
		AstToJson();

		~AstToJson();
		/**
		 * @brief Formal parser implementation ,return empty json object if find any semantic error
		 */
		Json parse(const ParseOption &option);
		/**
		 *@brief Used in spell complement ,always return valid AST for any input
		 */
		Json parseLoose(const ParseOption &option);
		/**
		 * @brief Helper function
		 */
		Json parse(const std::string &valueRaw);
		/**
		 * @brief Helper function
		 */
		Json parseLoose(const std::string &valueRaw);
		/**
		 * @brief Parse cyclone type annot to json
		 *
		 * @param annot
		 * @return Json
		 */
		Json parseType(const std::string &annot, const ParseTypeOption &option = ParseTypeOption());
		/**
		 * @brief Parse cyclone type annot to json
		 *
		 * @param annot
		 * @return Json
		 */
		Json parseTypeLoose(const std::string &annot, const ParseTypeOption &option = ParseTypeOption());
		/**
		 * @brief Get supported specialized rules , e.g. input, output ,vardecl
		 */
		static std::list<std::string> getSpecializedRuleNames();
		/**
		 * @brief Return true if json returned is a syntax error;
		 *
		 * @param parserResult
		 * @return true
		 * @return false
		 */
		static bool isSyntaxError(const Json &parserResult);
	};

} // namespace cyclone::parser

#endif
